﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:BusinessManager.Resources.Controls" 
                    xmlns:Converter="clr-namespace:BusinessManager.Helps" 
                    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                    xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell">

    <Converter:WindowActiveToColorConverter x:Key="WindowActiveToColorConverter" />
    <Converter:WindowActiveToBrushConverter x:Key="WindowActiveToBrushConverter"/>

    <Style x:Key="UserWindowStyle" TargetType="controls:UserWindow">
        <Setter Property="shell:WindowChrome.WindowChrome">
            <Setter.Value>
                <shell:WindowChrome CornerRadius="0" GlassFrameThickness="0" UseAeroCaptionButtons="False"  NonClientFrameEdges="None" />
            </Setter.Value>
        </Setter>
        <Setter Property="MinWidth" Value="100" />
        <Setter Property="MinHeight" Value="100" />
        <!-- <Setter Property="WindowStyle" Value="None"/> 
        <Setter Property="AllowsTransparency" Value="True"/>-->
        <Setter Property="Background" Value="{DynamicResource BgColor}"/> 
        <Setter Property="ResizeMode" Value="CanResizeWithGrip" /> 
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:UserWindow">
                    <Border  Padding="0" BorderThickness="1" BorderBrush="{Binding IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Converter={StaticResource WindowActiveToBrushConverter}}">
                        <Grid x:Name="LayoutRoot" Background="{TemplateBinding Background}" >
                            <Grid.Effect>
                                <DropShadowEffect Opacity="1" BlurRadius="8" ShadowDepth="1" Color="{Binding IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Converter={StaticResource WindowActiveToColorConverter}}"/>
                            </Grid.Effect>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="30"/>
                                <RowDefinition Height="5"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0"  >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="5"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Image Grid.Column="0" Source="{TemplateBinding Icon}" VerticalAlignment="Center" shell:WindowChrome.IsHitTestVisibleInChrome="True"/>
                                <TextBlock Grid.Column="1" Margin="5,0,0,0" Text="{TemplateBinding Title}" VerticalAlignment="Center" FontSize="14" Foreground="{DynamicResource FgColor}" TextTrimming="CharacterEllipsis"/>
                                <StackPanel Grid.Column="3" Orientation="Horizontal" shell:WindowChrome.IsHitTestVisibleInChrome="True">
                                    <Button x:Name="MiniBtn" Style="{DynamicResource MiniBtnStyle}" VerticalAlignment="Top" Height="23" Width="33" ToolTip="最小化" Command="{Binding Source={x:Static shell:SystemCommands.MinimizeWindowCommand}}">
                                        <Path Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" Stretch="Fill" Height="1.5" Width="15" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M0,5 C0,2.2385763 2.2385763,0 5,0 L95,0 C97.761424,0 100,2.2385763 100,5 C100,7.7614237 97.761424,10 95,10 L5,10 C2.2385763,10 0,7.7614237 0,5 z"/>
                                    </Button>
                                    <!--
                                    <Button x:Name="MaxBtn" Style="{DynamicResource MiniBtnStyle}" VerticalAlignment="Top" Height="23" Width="33" ToolTip="最大化" Command="{Binding Source={x:Static shell:SystemCommands.MaximizeWindowCommand}}">
                                        <Path Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" Stretch="Fill" Height="13" Width="15" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M7.0000005,14 L7.0000005,92.580002 92.580002,92.580002 92.580002,14 z M0,0 L99.580002,0 99.580002,99.580002 0,99.580002 z"/>
                                    </Button>
                                    <Button x:Name="RestoreBtn" Style="{DynamicResource MiniBtnStyle}" VerticalAlignment="Top" Height="23" Width="33" ToolTip="还原" Command="{Binding Source={x:Static shell:SystemCommands.RestoreWindowCommand}}">
                                        <Path Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" Stretch="Fill" Height="13" Width="15" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M6.0811005,24.07227 L6.0811005,93.06699 78.755674,93.06699 78.755674,24.07227 z M0,17.146168 L84.832818,17.146168 84.832818,100 0,100 z M15.171883,0 L100.00001,0 100.00001,82.855618 89.618004,82.855618 89.618004,75.927162 93.920941,75.927162 93.920941,6.9333534 21.246994,6.9333534 21.246994,12.126642 15.171883,12.126642 z"/>
                                    </Button>
                                    -->
                                    <controls:PathCheckBox x:Name="MaxBtn" VerticalAlignment="Top" CheckedData="M6.0811005,24.07227 L6.0811005,93.06699 78.755674,93.06699 78.755674,24.07227 z M0,17.146168 L84.832818,17.146168 84.832818,100 0,100 z M15.171883,0 L100.00001,0 100.00001,82.855618 89.618004,82.855618 89.618004,75.927162 93.920941,75.927162 93.920941,6.9333534 21.246994,6.9333534 21.246994,12.126642 15.171883,12.126642 z"
                                        CheckedDataWidth="15" CheckedDataHeight="13"
                                        UnCheckedData="M7.0000005,14 L7.0000005,92.580002 92.580002,92.580002 92.580002,14 z M0,0 L99.580002,0 99.580002,99.580002 0,99.580002 z "
                                        UnCheckedDataWidth="15" UnCheckedDataHeight="13"
                                        Stretch="Fill" Style="{DynamicResource MaxBtnStyle}"
                                        CheckedToolTip="还原" 
                                        UnCheckedToolTip="最大化"
                                        Height="23" Width="33">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Checked">
                                                <i:InvokeCommandAction Command="{Binding Source={x:Static shell:SystemCommands.MaximizeWindowCommand}}" />
                                            </i:EventTrigger>
                                            <i:EventTrigger EventName="Unchecked">
                                                <i:InvokeCommandAction Command="{Binding Source={x:Static shell:SystemCommands.RestoreWindowCommand}}" />
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </controls:PathCheckBox>
                                    <Button x:Name="CloseBtn" Style="{DynamicResource CloseBtnStyle}" VerticalAlignment="Top" Height="23" Width="33" ToolTip="关闭" Command="{Binding Source={x:Static shell:SystemCommands.CloseWindowCommand}}">
                                        <Path Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" Stretch="Fill" Height="12" Width="15" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M5.0000038,0 C6.2796135,0 7.559227,0.48815536 8.5355377,1.4644661 L49.790267,42.719195 91.044998,1.4644661 C92.997612,-0.48815155 96.163445,-0.48815536 98.116066,1.4644661 100.06869,3.4170837 100.06868,6.5829163 98.116066,8.5355301 L56.861335,49.790263 98.116066,91.044994 C100.06869,92.997612 100.06869,96.163441 98.116066,98.116062 96.163441,100.06869 92.997616,100.06868 91.044994,98.116066 L49.790265,56.861333 8.5355377,98.116062 C6.5829163,100.06868 3.4170914,100.06868 1.4644699,98.116062 -0.48815155,96.163441 -0.48815155,92.997616 1.4644699,91.044994 L42.719197,49.790266 1.4644699,8.5355377 C-0.48815536,6.5829163 -0.48815536,3.4170914 1.4644699,1.4644661 2.4407806,0.48815918 3.7203941,0 5.0000038,0 z" />
                                    </Button>
                                </StackPanel>
                            </Grid>
                            <Border Background="{TemplateBinding Background}" Grid.Row="2">
                                <ContentPresenter Content="{TemplateBinding Content}"/>
                            </Border>

                            <!-- resize grip -->
                            <ResizeGrip Grid.Row="2" x:Name="ResizeGrip" Width="6" Height="6" Margin="1" Background="Transparent" 
                            Visibility="Collapsed" HorizontalAlignment="Right" VerticalAlignment="Bottom" shell:WindowChrome.ResizeGripDirection="BottomRight"/>
                            
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="WindowState" Value="Maximized">
                            <!--
                            <Setter TargetName="MaxBtn" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="RestoreBtn" Property="Visibility" Value="Visible" />
                            -->
                            <Setter TargetName="MaxBtn" Property="IsChecked" Value="True"/>
                            <Setter TargetName="LayoutRoot" Property="Margin" Value="7"/>
                        </Trigger>
                        <Trigger Property="WindowState" Value="Normal">
                            <Setter TargetName="MaxBtn" Property="IsChecked" Value="False"/>
                            <!--
                            <Setter TargetName="MaxBtn" Property="Visibility" Value="Visible" />
                            <Setter TargetName="RestoreBtn" Property="Visibility" Value="Collapsed" />
                            -->
                        </Trigger>
                        <Trigger Property="ResizeMode" Value="NoResize">
                            <Setter TargetName="MiniBtn" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="MaxBtn" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="ResizeMode" Value="CanMinimize"> 
                            <Setter TargetName="MaxBtn" Property="Visibility" Value="Collapsed"/>
                        </Trigger> 
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="ResizeMode" Value="CanResizeWithGrip" />
                                <Condition Property="WindowState" Value="Normal" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ResizeGrip" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>

            </Setter.Value>
        </Setter>


    </Style>

</ResourceDictionary>